<template>
    <div id="seachDialog">
      <a-modal
      title="快速筛选"
      width="550px"
      :visible="searchData.show"
      @cancel="handleClose">
        <el-row style="padding:30px 70px 50px 20px;overflow-y:auto;overflow-x:hidden;">
            <el-form :model="searchParames" ref="searchParames" label-width="120px">
                <el-form-item label="联系人:">
                    <el-input  clearable size="small" v-model="searchParames.contacts" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="联系方式:" prop="mobile">
                    <el-row >
                        <el-col :span="8">
                        <el-select clearable size="small" v-model="searchParames.contactType" placeholder="请选择">
                            <el-option v-for="(item,index) in contactTypeData" :key="index" :label="item.desc" :value="item.name"></el-option>
                        </el-select>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable size="small" v-model="searchParames.mobile" placeholder="请输入"></el-input>
                        </el-col>
                    </el-row>
                </el-form-item>
                <el-form-item label="公司名称:"> <!-- 客户名称 -->
                    <el-input clearable size="small" v-model="searchParames.customerName" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="商机来源:">
                    <shangJi v-model="searchParames.opportunitySourceId" @checkValue="checkValue" :typeid="searchParames.opportunitySourceType" :id="searchParames.opportunitySourceId" :type="'new'"></shangJi>
                </el-form-item>
                <el-form-item label="紧急程度:">
                    <el-select clearable size="small" v-model="searchParames.urgencyLabel"  placeholder="请选择优先级">
                        <el-option v-for="(item,index) in urgencyData" :key="index" :label="item.desc" :value="item.name"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="重要程度:">
                    <el-select clearable size="small" v-model="searchParames.importanceLabel" placeholder="请选择客户喜好">
                        <el-option v-for="(item,index) in importData" :key="index" :label="item.desc" :value="item.name"></el-option>
                    </el-select>
                </el-form-item>
                <!-- <el-form-item label="下次跟进时间:">
                    <el-date-picker
                    style="width:100%"
                    size="small"
                    v-model="searchParames.nextFollowDate"
                    type="date"
                    placeholder="选择日期">
                    </el-date-picker>
                </el-form-item> -->
                <el-form-item label="负责人:">
                    <userTree clearable v-model="searchParames.directorId" :currentValue="searchParames.directorId"></userTree>
                </el-form-item>
            </el-form>
        </el-row>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="handleReset">重置</el-button>
            <el-button size="small" type="primary" @click="handleSend">查询</el-button>
        </span>
      </a-modal>
    </div>
</template>

<script>
export default {
    props: ['searchData'],
    data() {
        return {
          searchParames: {
            contacts: '', //联系人
            contactType: '', //联系方式
            mobile: '', //联系手机号
            customerName: '', //客户名称
            opportunitySourceType: '', //商机来源类型
            opportunitySourceId: '', //商机来源
            urgencyLabel: '', //紧急程度
            importanceLabel: '',//重要程度
            directorId: '', //当前负责人
          },
          contactTypeData: [], //联系方式
          importData: [], //重要程度
          urgencyData: [], //紧急程度
        };
    },
    methods: {
        handleSend () {
            let searchDate = []
            for(var key in this.searchParames){
                if (this.searchParames[key]) {
                    if (key == 'contactType' || key == 'opportunitySourceType' || key == 'importanceLabel' || key == 'urgencyLabel') {
                        searchDate.push({
                            key: key,
                            value: this.searchParames[key],
                            type: 'enumeration'
                        })
                    } else {
                        searchDate.push({
                            key: key,
                            value: this.searchParames[key],
                            type: 'string'
                        })
                    }
                }
            }
            this.$emit('checkSearch',searchDate)
            this.handleClose()
        },
        checkValue (value) { //来源获取信息
            this.searchParames.opportunitySourceType = value
        },
        handleClose () {
            this.searchData.show = false
        },
        handleReset () {
            this.searchParames.contacts = '' //联系人
            this.searchParames.contactType = '' //联系方式
            this.searchParames.mobile = '' //联系手机号
            this.searchParames.customerName = '' //客户名称
            this.searchParames.opportunitySourceType = '' //商机来源类型
            this.searchParames.opportunitySourceId = '' //商机来源
            this.searchParames.urgencyLabel = '' //紧急程度
            this.searchParames.importanceLabel = ''//重要程度
            this.searchParames.directorId = '' //当前负责人
            this.$emit('resetSearch')
            this.$refs.searchParames.resetFields()
        }
    },
    computed: {
      changeDialog () {
        return this.searchData.show
      }
    }, 
    watch: {
      changeDialog: {
        handler (curVal, oldVal) {
          if (curVal) {
            this.$utils.getEnumberation('postContactType','contactTypeData',this) //获取联系方式
            this.$utils.getEnumberation('postOpportunityImportanceLabel','importData',this) //重要程度
            this.$utils.getEnumberation('postOpportunityUrgencyLabel','urgencyData',this) //紧急程度
            this.searchParames.customerName = this.searchData.customerName
          } else {
          }
        }
      }
    },
};
</script>

<style>
#seachDialog .el-dialog{
    padding-bottom: 0; 
    overflow-x: hidden;
}
#seachDialog .el-dialog__footer{
    border-top: #f4f4f4 solid 1px;
}
.ant-modal-body{
    padding: 0
}
</style>
